package com.bwie.common.handler;

import com.bwie.common.exceptions.LiteratureInfoExceptions;
import com.bwie.common.exceptions.UserLoginExceptions;
import com.bwie.common.result.Result;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @className: GlobalExceptionsHandler
 * @Description: TODO
 * @version: v1.８.0
 * @author: 李明
 * @date: 2025/11/10 10:27
 */
@RestControllerAdvice
@Log4j2
public class GlobalExceptionsHandler {


    @ExceptionHandler(UserLoginExceptions.class)
    public Result UserLoginExceptions(UserLoginExceptions userLoginExceptions){
        log.info("全局异常处理器，异常编码：{}， 异常信息：{}",
                userLoginExceptions.getCode(),userLoginExceptions.getMessage());
        return Result.error(userLoginExceptions.getCode(), userLoginExceptions.getMessage());
    }


    @ExceptionHandler(LiteratureInfoExceptions.class)
    public Result LiteratureInfoExceptions(LiteratureInfoExceptions literatureInfoExceptions){
        log.info("全局异常处理器，异常编码：{}， 异常信息：{}",
                literatureInfoExceptions.getCode(),literatureInfoExceptions.getMessage());
        return Result.error(literatureInfoExceptions.getCode(), literatureInfoExceptions.getMessage());
    }


}
